package any.impl.util;

import java.util.Iterator;
import java.util.Map.Entry;

import any.SequentialAny;


public class EntriesIterableAdapter<T extends SequentialAny> implements Iterable<T> {

	private final Iterable<? extends Entry<String, ? extends SequentialAny>> entriesIterable;

	public EntriesIterableAdapter(Iterable<? extends Entry<String, T>> entriesIterable) {
		this.entriesIterable = entriesIterable;
	}
	
    public Iterator<T> iterator() {
	    return new Itr(entriesIterable.iterator());
    }

	class Itr implements Iterator<T> {
		private final Iterator<? extends Entry<String, ? extends SequentialAny>> entriesItr;

		Itr(Iterator<? extends Entry<String, ? extends SequentialAny>> entriesIt) {
			this.entriesItr = entriesIt;
		}

		public boolean hasNext() {
			return entriesItr.hasNext();
		}
		
		@SuppressWarnings("unchecked")
        public T next() {
			return (T)entriesItr.next().getValue();
		}
		
		public void remove() {
			entriesItr.remove();
		}
	}
	
}